<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('采购报错单')"/>
    <th:block th:include="include :: list-css"/>
    <style type="text/css">
        .layui-tab-title {
            border-color: #ccc !important;
        }

        .layui-this {
            color: rgb(0, 135, 250) !important;
            background: none !important;
        }

        .layui-tab-brief > .layui-tab-title .layui-this:after, .layui-tab-brief > .layui-tab-more li.layui-this:after {
            border-color: rgb(0, 135, 250) !important;
        }

        label.layui-form-label {
            width: 95px;
            padding-right: 0px;
        }

        .layui-form-radio {
            margin-top: 0
        }

        .mid-content {
            overflow-y: auto
        }

        .importTable {
            empty-cells: show;
            border-collapse: collapse;
            border-spacing: 0;
        }

        .listext th {
            background: #eee;
            color: #3366cc;
        }

        .listext th, .listext td {
            border: solid 1px #ddd;
            text-align: left;
            padding: 10px;
            font-size: 14px;
        }

        #importProgress {
            z-index: 20200202;
            background-color: #000;
            opacity: 0.3;
            display: none;
        }

        .importProgress {
            width: 300px;
            z-index: 20202222;
            position: fixed;
            top: 34%;
            left: 40%;
            display: none;
        }

        .istype0 {
            height: 28px;
            line-height: 28px;
        }

        .istype1 {
            display: none;
            height: 28px;
            line-height: 28px;
            display: inline-block;
        }

        .istype2 {
            display: none;
            height: 28px;
            line-height: 28px;
            display: inline-block;
        }

        .istype3 {
            display: none;
            height: 28px;
            line-height: 28px;
            display: inline-block;
        }
    </style>
</head>
<body>
<div class="main-content">
    <div class="content-right">
        <div class="search-top">
            <span>查询条件</span>
            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
                <i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
            </a>
        </div>
        <div class="panel layout-expand layui-expand-east">
            <div class="panel-header">
                <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
                    <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
                        <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
                    </a>
                </div>
            </div>
            <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
        </div>
        <form class="layui-form">
            <th:block th:include="listinclude :: searchRight('page')"/>
        </form>
    </div>
    <div class="mid-content">
        <div class="layui-tab layui-tab-brief istype" lay-filter="demo1" style="margin-top: 0;">
            <ul class="layui-tab-title">
                <li name="申请退货" th:if="${vtype != 2}" class="layui-this">申请退货</li>
                <li name="仓库处理" th:if="${vtype != 2}">仓库处理</li>
                <li name="采购处理" th:if="${vtype != 1}">采购处理</li>
                <li name="已完成">已完成</li>
            </ul>
            <div class="layui-tab-content"></div>
        </div>
        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>

    </div>
</div>
<!-- 表格头部工作栏-->
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <span class="ishide0">
            <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn">
                <i class="dhicon dh-lujing1089"></i> 新增
            </div>
            <div class="layui-btn layui-table-tools importbtn-bg" lay-event="shbtn1" th:if="${extraButton.shbtn1}">
                <i class="dhicon layui-icon-set-fill"></i> 审核
            </div>
            <div class="layui-btn layui-btn-danger layui-table-tools" onclick="remove()" th:if="${extraButton.delbtn}">
                <p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">批量删除</span></p>
            </div>
        </span>
        <span class="ishide1">
			<div class="layui-btn layui-table-tools importbtn-bg" lay-event="shbtn2" th:if="${extraButton.shbtn2}">
                <i class="dhicon layui-icon-set-fill"></i> 审核
            </div>
            <div class="layui-btn layui-table-tools importbtn-bg" lay-event="htbtn2" th:if="${extraButton.htbtn2}">
				<i class="dhicon layui-icon-prev"></i> 回退
			</div>
		</span>
        <span class="ishide2">
			<div class="layui-btn layui-table-tools importbtn-bg" lay-event="shbtn3" th:if="${extraButton.shbtn3}">
                <i class="dhicon layui-icon-set-fill"></i> 审核
            </div>
            <div class="layui-btn layui-table-tools importbtn-bg" lay-event="htbtn3" th:if="${extraButton.htbtn3}">
				<i class="dhicon layui-icon-prev"></i> 回退
			</div>
		</span>
        <span class="ishide3">
		    <div class="layui-btn layui-table-tools importbtn-bg ishide3" lay-event="htbtn4" th:if="${extraButton.htbtn4}">
                <i class="dhicon layui-icon-prev"></i> 回退
            </div>
		</span>



    </div>
</script>

<!-- 表格操作区 -->
<script type="text/html" id="yybl">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto tccon">
        <div class="layui-form-item margin_t0">
            <input type="hidden" name="czguid" id="czguid" th:value="${cost?.guid}" class="layui-input canntEdit"
                   autocomplete="off" readonly/>
            <div class="layui-inline margin_r0 layui-col-xs12">
                <label class="layui-form-label"><font>报错费用：</font></label>
                <div class="layui-input-block"><input type="number" name="errorCost" id="errorCost"
                                                      th:value="${cost?.errorCost}" class="layui-input"
                                                      autocomplete="off"/></div>
            </div>
        </div>
    </div>
</script>
<!-- 表格操作区 -->
<script type="text/html" id="barDh">
    <a class="layui-btn layui-btn-danger layui-btn-xs istype0"  onclick="path('{{d.nid}}','0')">修改</a>
 <a class="layui-btn layui-btn-danger layui-btn-xs istype1" th:if="${extraButton.bcsmbtn}"
       onclick="path('{{d.nid}}','1')">仓库处理</a>
    <a class="layui-btn layui-btn-disabled layui-btn-xs istype1" th:if="!${extraButton.bcsmbtn}">仓库处理</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs istype2" th:if="${extraButton.cgclbtn}"
       onclick="path('{{d.nid}}','2')">采购处理</a>
    <a class="layui-btn layui-btn-disabled layui-btn-xs istype2" th:if="!${extraButton.cgclbtn}">采购处理</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs istype3" onclick="path('{{d.nid}}','3')">查看详情</a>
</script>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: businessJS"/>
<th:block th:include="include :: searchJS"/>
<th:block th:include="listinclude :: list-templeat"/>
<script th:inline="javascript">
    /*<![CDATA[*/
    var prefix = ctx + "purchase/refund";
    var tableUrl = "";
    var gridColumns = [[${gridColumns}]],
        importFields = [[${importFields}]],
        extraButton = [[${extraButton}]],
        moduleTable = [[${moduleTable}]];
    vtype = [[${vtype}]];
    tableUrl = "/purchase/refund/list?state=0";

    /*]]>*/
</script>
<script type="text/javascript">
    var element, thStr;
    var fieldWidth = {},		//导入列表字段宽度
        filedRequired = {},		//导入列表必填字段
        dateFiled = [],			//导入列表日期字段
        hasNull = false;		//导入数据必填字段有空值
    $.each(gridColumns.dictionaryForPageFieldList, function (i, v) {
        fieldWidth[v.fields] = v.fieldFrontWidth
        if (v.fieldFrontRequired) filedRequired[v.fields] = v.fieldName;
        if (v.fieldFrontType == 't_date') dateFiled.push(v.fields);
    })
    var $, layer, laydate, form, table, wherestr = {};
    layui.use(['table', 'laydate', 'form', 'layer', 'jquery', 'element'], function () {
        $ = layui.$, layer = layui.layer, laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
        serachRender();//查询条件初始渲染集合
        changeDropdown('fSl');//导入窗口——税率下拉可编辑赋事件
        //是否显示头部按钮
        var vtype = 0
        $.tablelist.init({
            elem: '#dhtable'
            , modalName: "产品信息"
            , url: tableUrl
            , updateUrl: prefix + "/edit?guid={id}"
            , initSort: {field: 'createTime', type: 'asc'}
            , totalRow: gridColumns.totalRow
            , cols: [gridColumns.gridBody]
            , toolbar: '#toolbar'
            , height: 'full-46'
            , defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}] //这里在右边显示
            , parseData: function (res) { //res 即为原始返回的数据
                var objpage = sessionStorage.getItem(moduleTable + 'checkdata')
                if (objpage) {
                    objpage = JSON.parse(objpage)
                    res.data.map((v, i) => {
                        objpage.map((n, m) => {
                            if (v.guid == n.guid) {
                                v.LAY_CHECKED = true
                            }
                        })
                    })
                }
            }
            , done: function (res, curr, count) {
                var ltv = this.elem.next('.layui-table-view');//当前table的dom
                res.data.length || count || ltv.find('.layui-table-header').css('display', 'inline-block');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
                res.data.length || count || ltv.find('.layui-table-box').css('overflow-x', 'auto');//数量为0时(统计报表存在不传count的情况)，表头赋予样式可拉动
                $('.ishide0').hide()
                $('.ishide1').hide()
                $('.ishide2').hide()
                $('.ishide3').hide()
                $('.istype1').hide()
                $('.istype0').hide()
                $('.istype2').hide()
                $('.istype3').hide()
                console.log(111,vtype)
                if(vtype==0){
                    $('.ishide0').show()
                    $('.istype0').show()
                }else if(vtype==1){
                    $('.ishide1').show()
                    $('.istype1').show()
                }else if(vtype==2){
                    $('.ishide2').show()
                    $('.istype2').show()
                }else if(vtype==3){
                    $('.ishide3').show()
                    $('.istype3').show()
                }
                fixTotal(this);//修复合计行固定列问题
                rowheight(res, curr);//修复合计行固定列问题
                if (typeof listTableDone == 'function') listTableDone();//如果查询列表存在表格加载完成回调事件，则执行
            }
        });
        //监听排序事件 
        table.on('sort(ftable)', function (obj) {
            $.tablelist.sort('dhtable', obj);
        });

        //监听行双击事件
        table.on('rowDouble(ftable)', function (obj) {
            console.log("===========rowDouble ");
            console.log(obj);
            // window.location.href = "/business/productbasis/edit?guid="+obj.data.guid;
            // top.layui.index.openTabsPage(prefix+ "/edit?nid="+obj.data.nid,'采购报错单 - 修改')

        });

        window.path = function (nid, vType) {
            top.layui.index.openTabsPage(prefix + "/edit?nid=" + nid + '&vType=' + vType, '采购退货单 - 修改')
        }
        // 多选赋值
        sessionStorage.setItem(moduleTable + 'checkdata', '')
        table.on('checkbox(ftable)', function (obj) {
            var objpage = sessionStorage.getItem(moduleTable + 'checkdata')
            if (obj.type == 'all') {//判断是否全选
                var objdata = table.checkStatus('dhtable')
                objdata = objdata.data
                if (obj.checked) {//判断是否选中
                    if (objpage) {
                        objpage = JSON.parse(objpage)
                        objpage = objpage.concat(objdata)
                        objpage = newData(objpage)
                    } else {
                        objpage = objdata
                    }
                } else {
                    var objpage = JSON.parse(objpage)
                    var deldata = table.cache.dhtable
                    objpage = delData(objpage, deldata)
                }
                sessionStorage.setItem(moduleTable + 'checkdata', JSON.stringify(objpage))

            } else {//点击复选框
                if (objpage) {
                    objpage = JSON.parse(objpage)
                    if (obj.checked) {
                        objpage.push(obj.data)
                    } else {
                        objpage.map((v, i) => {
                            if (v.guid == obj.data.guid) {
                                objpage.splice(i, 1)
                            }
                        })
                    }
                } else {
                    objpage = []
                    objpage.push(obj.data)
                }
                sessionStorage.setItem(moduleTable + 'checkdata', JSON.stringify(objpage))
            }
        });
        //头工具栏事件
        $('.zjbcbtn').click(function () {
            $.post(prefix + '/editpost', {'infoItems': JSON.stringify(table.cache.pdhtable)}, function (res) {
                layer.msg(res.msg);
            });
        })
// 头部组装切换
        element.on('tab(demo1)', function (elem, a) {
            var name = $(elem.elem.context).text()
            if (name == '仓库处理') {
                tableUrl = "/purchase/refund/list?state=1"
            } else if (name == '采购处理') {
                tableUrl = "/purchase/refund/list?state=2"
            } else if (name == '已完成') {
                tableUrl = "/purchase/refund/list?state=3"
            } else {
                tableUrl = "/purchase/refund/list?state=0"
            }
            table.reload('dhtable', {url: tableUrl});
            if (name == '申请退货') {
                vtype = 0
                $('.ishide0').show()
                $('.ishide1').hide()
                $('.ishide2').hide()
                $('.ishide3').hide()
            } else if (name == '仓库处理') {
                vtype = 1
                $('.ishide0').hide()
                $('.ishide1').show()
                $('.ishide2').hide()
                $('.ishide3').hide()
            } else if (name == '采购处理') {
                vtype = 2
                $('.ishide0').hide()
                $('.ishide1').hide()
                $('.ishide2').show()
                $('.ishide3').hide()
            } else {
                vtype = 3
                $('.ishide0').hide()
                $('.ishide1').hide()
                $('.ishide2').hide()
                $('.ishide3').show()
            }
        });

        function statejk(msg, state) {
            var objpage = sessionStorage.getItem(moduleTable + 'checkdata')
            if (!objpage) {
                layer.msg("请先选择数据！");
            } else {
                $.modal.confirmCom(msg, function (result) {
                    var infoItems = JSON.parse(objpage)
                    var dataAll = []
                    $.each(infoItems, function (i, v) {
                        dataAll.push({'nid': v.nid,'guid': v.guid, 'state': state, 'effectStock': v.effectStock})
                    })
                    $.operate.post(prefix + '/updateType', {infoItems: JSON.stringify(dataAll)}, function (result) {
                        setTimeout(function () {
                            sessionStorage.setItem(moduleTable + 'checkdata', '')
                            table.reload('dhtable', {page: {curr: 1}, where: getWherestr()});
                        }, 1000);
                    });
                });
            }
        }


        //头工具栏事件
        table.on('toolbar(ftable)', function (obj) {
            switch (obj.event) {
                case 'shbtn1'://未处理审核
                    statejk('确定要审核么？', '1')
                    break;
                case 'shbtn2'://采购审核
                    statejk('确定要审核么？', '2')
                    break;
                case 'shbtn3'://采购审核
                    statejk('确定要审核么？', '3')
                    break;
                case 'htbtn2'://回退
                    statejk('确定要回退么？', '0')
                    break;
                case 'htbtn3'://回退
                    statejk('确定要回退么？', '1')
                    break;
                case 'htbtn4'://回退
                    statejk('确定要回退么？', '2')
                    break;
                case 'exportbtn':
                    $.ajax({
                        url: '/purchase/refund/export',
                        type: 'GET',
                        data: getWherestr(),
                        dataType: 'json',
                        beforeSend: function () {
                            showloadings(true);
                        },
                        success: function (result) {
                            if (result.code == 0) {
                                window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
                                parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
                            } else if (result.code == web_status.WARNING) {
                                $.modal.alertWarning(result.msg)
                            } else {
                                $.modal.alertError(result.msg);
                            }
                            showloadings(false);
                        }
                    });
                    break;
                case 'tableFull'://表格展开
                    $('.north .layui-form').hide();
                    table.reload('dhtable', {
                        defaultToolbar: [{title: '收缩', layEvent: 'tableShrink', icon: 'layui-icon-screen-restore'}],
                        height: $(window).height() - $('.north').height() - 60 < 300 ? '300' : $(window).height() - ($('.north').height() + $('.south').height() + 12)
                    });
                    break;
                case 'tableShrink'://表格收缩
                    $('.north .layui-form').show();
                    table.reload('dhtable', {
                        defaultToolbar: [{title: '展开', layEvent: 'tableFull', icon: 'layui-icon-screen-full'}],
                        height: $(window).height() - $('.north').height() - 60 < 300 ? '300' : $(window).height() - ($('.north').height() + $('.south').height() + 12)
                    });
                    break;
                case 'fieldSet':
                    filedSet(moduleTable);
                    break;
                case 'addbtn':
                    top.layui.index.openTabsPage(prefix+ "/edit?vType=0",'采购退货 - 新增')
                    break;
            }
            ;
        });
    });

    //通过guid彻底删除
    function remove() {
        var objpage = sessionStorage.getItem(moduleTable + 'checkdata')
        if (!objpage) {
            layer.msg("请先选择数据！");
        } else {
            $.modal.confirmCom('确定要删除么？', function (result) {
                var infoItems = JSON.parse(objpage)
                $.operate.post('/purchase/refund/delete', {infoItems: JSON.stringify(infoItems)}, function (result) {
                    setTimeout(function () {
                        table.reload('dhtable', {page: {curr: 1}, where: getWherestr()});
                    }, 1000);
                });
            });
        }
    }

</script>
</body>
</html>